package design_pattern;



public class ProxyPattern {
    public static void main(String[] args) throws IllegalAccessException, InstantiationException, ClassNotFoundException {
        new RealSubjectProxy().doWork();
    }
}
interface Subject{
    void doWork();
}
class RealSubject implements Subject{

    @Override
    public void doWork() {
        System.out.println("Hello World!");
    }
}
class RealSubjectProxy implements Subject{
    private RealSubject realSubject;

    public RealSubjectProxy() throws ClassNotFoundException, IllegalAccessException, InstantiationException {
        this.realSubject = (RealSubject) this.getClass().getClassLoader().loadClass("design_pattern.ProxyPattern").newInstance();
    }
    @Override
    public void doWork() {
        System.out.println("doWork前方法");
        realSubject.doWork();
        System.out.println("doork后方法");
    }
}